package com.yj.util;



import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yj.entity.Houses;
import com.yj.vo.JsonResult;




public class PageUtil {

	private static PageHelper helper = new PageHelper();
	
	
	
	public static  PageInfo test(int pageNum,int pageSize,BaseMapper mapper,QueryWrapper wrapper) {
		helper.startPage(pageNum, pageSize);
		
		return new PageInfo(mapper.selectList(wrapper));
		
	
	}
	
	//查询页码
	public static JsonResult pages(BaseMapper mapper,QueryWrapper wrapper,int pageSize) {
		JsonResult ret = null;
		PageInfo<Houses> pageInfo = PageUtil.test(0, pageSize, mapper, wrapper);
		int[] nums = pageInfo.getNavigatepageNums();
		if (nums != null && nums.length != 0) {
			ret = new JsonResult(true, "页码查询成功");
			ret.setData("pages", nums);
			return ret;
		} else {
			ret = new JsonResult(false, "页码查询失败");
			return ret;
		}
	}
	
	
	//查询当前页的数据
	public static JsonResult page(int pageNum,int pageSize,BaseMapper mapper,QueryWrapper wrapper) {
		JsonResult ret = null;
		PageInfo pageInfo = PageUtil.test(pageNum, pageSize, mapper, wrapper);
		List list = pageInfo.getList();
		if (list != null && pageInfo.getNavigatepageNums().length != 0) {
			ret = new JsonResult(true, "当前页数据查询成功");
			ret.setData("page", list);
			return ret;
		} else {
			ret = new JsonResult(false, "当前页查询失败");
			return ret;
		}
	}
	
	
	
	
	
}
